package command.usuario;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import model.Pasta;

import command.ICommand;

import dao.assinatura.PastaDAO;
import dao.fabrica.FabricaDAO;

public class DeletarPastaCommand implements ICommand {
	
	private String pastaId;
	
	public String execute(HttpServletRequest request) throws ServletException, IOException {
		
		
		try {
			
			
			pastaId = request.getParameter("p"); 
			if (pastaId != null )
			{

				PastaDAO pastaDAO = FabricaDAO.createPasta();
		
				Pasta pasta = pastaDAO.getPastaById(Integer.parseInt(pastaId));	
				
				if (pasta != null){
					pastaDAO.deletePasta(Integer.parseInt(pastaId));
				}
			 
			}else{
				 return "/paginas/inicio.jsp?resultado=FALSE";
				 
			 }
			 
			
			
		} catch (SQLException e) {
			e.printStackTrace();
			return "/paginas/cadastro/cadastro_invalido.jsp";
		}
	return "/paginas/inicio.jsp?resultado=OK";

}
}
